<template>
    <div :style="{ padding: (isFirst ? '8px' : '0px'),width:isCollapse?'auto':'200px' }">
        <el-skeleton animated :loading="isFirst" :rows="10">
            <el-menu :collapse="isCollapse" :router="true" default-active="2" class="el-menu-vertical-demo">
                <template v-for="item in menus">
                    <template v-if="item.children.length === 0">
                        <el-menu-item :index="item.url">

                            <i :class="item.icon"></i> <span slot="title">{{ item.name }}</span>
                        </el-menu-item>
                    </template>
                    <template v-else>
                        <el-submenu :index="item.url">
                            <template slot="title">
                                <i :class="item.icon"></i> <span>{{ item.name }}</span>
                            </template>
                            <el-menu-item v-for="item2 in item.children" :index="item2.url">
                                <i :class="item2.icon"></i> {{ item2.name }}</el-menu-item>

                        </el-submenu>
                    </template>
                </template>

                <!-- <el-submenu index="1">
                <template slot="title">
                    <i class="el-icon-location"></i>
                    <span>导航一</span>
                </template>
                <el-menu-item-group>
                    <template slot="title">分组一</template>
                    <el-menu-item index="1-1">选项1</el-menu-item>
                    <el-menu-item index="1-2">选项2</el-menu-item>
                </el-menu-item-group>
                <el-menu-item-group title="分组2">
                    <el-menu-item index="1-3">选项3</el-menu-item>
                </el-menu-item-group>
                <el-submenu index="1-4">
                    <template slot="title">选项4</template>
                    <el-menu-item index="1-4-1">选项1</el-menu-item>
                </el-submenu>
            </el-submenu>
            <el-menu-item index="2">
                <i class="el-icon-menu"></i>
                <span slot="title">导航二</span>
            </el-menu-item>
            <el-menu-item index="3" disabled>
                <i class="el-icon-document"></i>
                <span slot="title">导航三</span>
            </el-menu-item>
            <el-menu-item index="4">
                <i class="el-icon-setting"></i>
                <span slot="title">导航四</span>
            </el-menu-item> -->
            </el-menu>
        </el-skeleton>
    </div>
</template>
<style>
.el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
}



</style>
<script>
import { get_menus } from '@/api/index'

export default {
    data: () => {
        return {
            isFirst: true,
            menus: [],
            isCollapse: false,
        }
    },
    methods: {
        async bind() {
            const res = await get_menus();
            if (res.code === 0) {

                this.menus = res.data;
                console.log(this.menus);
                this.isFirst = false;
            }
        }
    },
    mounted: function () {
        if (parseInt(window.innerWidth) < 800) {
                this.isCollapse = true;
            } else {
                this.isCollapse = false;
            }
        window.addEventListener("resize", () => {
            if (parseInt(window.innerWidth) < 800) {
                this.isCollapse = true;
            } else {
                this.isCollapse = false;
            }
        });

        this.bind();

    }

    //菜单应该是动态的
}


</script>